﻿Imports TNCBAL
Imports TNCDAL

Public Class ucFileMBLGridView
    Private _objFileMBLController As New FileMBLController
    Private _objFile As tblFile ' Thông tin File

    ''' <summary>
    ''' Gọi hàm khởi tạo này nếu muốn lấy toàn bộ các MBL
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()
        InitializeComponent()
        BindingDataGridView(Nothing)
        FormatDataGridView()
    End Sub

    ' ''' <summary>
    ' ''' Gọi hàm khởi tạo này nếu muốn lấy các MBL của một File
    ' ''' </summary>
    ' ''' <param name="obj"></param>
    ' ''' <remarks></remarks>
    'Public Sub New()
    '    InitializeComponent()

    'End Sub

    'Public ReadOnly Property CurrentRow() As DataGridViewRow
    '    Get
    '        Return dataGridViewXMBL.CurrentRow
    '    End Get
    'End Property

    Public ReadOnly Property DataGridView() As DevComponents.DotNetBar.Controls.DataGridViewX
        Get
            Return dataGridViewXMBL
        End Get
    End Property

    Public Sub BindingDataGridView(ByVal obj As tblFile, Optional ByVal indexRow As Integer = -1)
        'Lưu thông tin File
        _objFile = obj
        Dim query As IQueryable
        If _objFile IsNot Nothing Then
            query = _objFileMBLController.GetCustomFileMBLList(_objFile.ID_File)
        Else
            query = _objFileMBLController.GetCustomFileMBLList(-1)
        End If

        If indexRow > 0 Then
            'Set current row
            dataGridViewXMBL.Rows(indexRow).Selected = True
            dataGridViewXMBL.FirstDisplayedScrollingRowIndex = indexRow
        End If

        dataGridViewXMBL.DataSource = query
        dataGridViewXMBL.Columns("ID_FileMBL").Visible = False
        dataGridViewXMBL.Columns("tblFile").Visible = False
    End Sub

    Public Sub FormatDataGridView()
        dataGridViewXMBL.AllowUserToAddRows = False
        dataGridViewXMBL.AllowUserToDeleteRows = False
        dataGridViewXMBL.ReadOnly = True
        dataGridViewXMBL.SelectionMode = DataGridViewSelectionMode.CellSelect
        dataGridViewXMBL.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
    End Sub

    Public dataGridViewXMBL_CurrentCellChangedEvent As EventHandler
    Private Sub dataGridViewXMBL_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dataGridViewXMBL.CurrentCellChanged
        If dataGridViewXMBL_CurrentCellChangedEvent IsNot Nothing Then
            dataGridViewXMBL_CurrentCellChangedEvent(sender, e)
        End If
    End Sub

    Private Sub dataGridViewXMBL_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dataGridViewXMBL.CellContentClick

    End Sub
End Class
